package com.dingding.commonservice.core.city.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.dingding.common.core.base.daox.IBaseDaoX;
import com.dingding.common.core.base.daox.ISQLBaseDao;
import com.dingding.common.core.beans.City;
import com.dingding.commonservice.core.city.dao.ICityDao;
import com.dingding.commonservice.core.city.sql.CitySQL;
import com.dingding.facade.commonservice.common.dto.city.ResOpenCityDTO;

/**
 * 
 * @ClassName: CityDaoImpl 
 * @Description: 开通城市Dao实现类
 * @author YHQ
 * @date 2016年12月1日 下午3:21:14
 * @since V2.5.6
 * 
 */
@Component("openCityDao")
public class CityDaoImpl implements ICityDao{

	@Resource(name = "baseDaoX")
	private IBaseDaoX baseDaoX;
	
	@Resource(name = "SQLBaseDao")
	private ISQLBaseDao sqlBaseDao;
	
	private Logger log = Logger.getLogger(this.getClass());
	
	/**
	 * 
	 * @Title: geCityDTOs 
	 * @Description: 获取开通城市列表 
	 * @author YHQ 
	 * @return List<ResOpenCityDTO>    返回类型
	 * 
	 */
	@Transactional(readOnly = true)
	public List<ResOpenCityDTO> geCityDTOs() {
		
		try {
			
			return sqlBaseDao.listSqlToCustomBean(ResOpenCityDTO.class, CitySQL.GET_OPEN_CITY_LIST);
		} catch (Exception e) {
			log.error("获取开通城市列表时出现异常  类：" + this.getClass() + " geCityDTOs()", e);
		}
		
		return null;
	}

	/**
	 * 
	 * @Title: isServiceCity 
	 * @Description: 根据城市编号获取城市信息
	 * @param cityNo 城市编号
	 * @author YHQ 
	 * @since V2.5.7
	 * @return City  城市信息
	 * 
	 */
	@Override
	@Transactional(readOnly = true)
	public City isServiceCity(String cityNo) {
		
		try {
			return sqlBaseDao.sqlToCustomBeanUnique(City.class, CitySQL.GET_CITY_BY_CITYNO, cityNo);
		} catch (Exception e) {
			log.error("根据城市编号获取城市信息时出现异常   类：" + this.getClass() + " isServiceCity()", e);
		}
		
		return null;
	}

	@Override
	@Transactional(readOnly = true)
	public ResOpenCityDTO getCityDTO(Integer cityId) {
		
		try {
			return sqlBaseDao.sqlToCustomBeanUnique(ResOpenCityDTO.class, CitySQL.GET_OPEN_CITY_BY_ID, cityId);
		} catch (Exception e) {
			log.error("获取开通城市列表时出现异常  类：" + this.getClass() + " geCityDTOs()", e);
		}
		return null;
	}

	
}
